package besuper;

import java.util.Random;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "questions")
public class Question {
	public Question() {
	}

	private static int numOfQuestions=new Random().nextInt(100)+1000;
	
	public Question(String content,Player player) {
		this.content=content;
		this.id = ++numOfQuestions;
		this.asker = player;
	}

	@XmlElement(name = "提问人")
	private Player asker;
	
	@XmlAttribute(name = "id")
	private int id;
	
	@XmlElement(name = "内容")
	private String content;
	
	@XmlElement(name = "答案")
	private Answer ans;
	
	@XmlElement(name = "solved")
	private boolean isSolved;
	
	public boolean isSolved() {
		return isSolved;
	}
	
	public Player getAsker() {
		return asker;
	}

	public void setAsker(int idOfPlayer,String name) {
		this.asker = new Player();
	}

	public void setSolved(boolean isSolved) {
		this.isSolved = isSolved;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public Answer getAns() {
		return ans;
	}

	public void setAns(String content, Player anser) {
		this.ans = new Answer(content,anser);
		this.isSolved = true;
	}

	public String printQuestion() {
		String s = "";
		s+="\nquestion: \n";
		s+="id: "+id;
		s+=" 提问者： "+this.getAsker().getName();
		s+="\n内容: \""+content+"\", 状态: ";
		s+= isSolved?"已被":"待";
		s+="解决\n";
		return s;
	}
	
	public String printQusetionWithAnswer(){
		String s = printQuestion();
		s+="-----------------";
		s+=ans.toString();
		s+="\n";
		return s;
	}
}
